$(document).ready(function() {
	$('#forgetPasswordButton').click(function() {
		
                //Getting the variable's value from a link 
//		var loginBox = $(this).attr('href');]
		var loginBox = '#forgetDiv';

		//Fade in the Popup
		$(loginBox).fadeIn(300);
		
		//Set the center alignment padding + border see css style
		var popMargTop = ($(loginBox).height() + 24) / 2; 
		var popMargLeft = ($(loginBox).width() + 24) / 2; 
		
		$(loginBox).css({ 
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});
		
		// Add the mask to body
		$('body').append('<div id="mask"></div>');
		var height = $(document).height();
		$('#mask').height(height);
		$('#mask').fadeIn(300);
		
		return false;
	});
	
	// When clicking on the button close or the mask layer the popup closed
//	$('a.close, #mask').live('click', function() {
	$('a.close').click(function() {
	  $('#mask , .forget-popup').fadeOut(300 , function() {
		$('#mask').remove();  
	}); 
	return false;
	});
	
	$('#forgetSubmit').click(function() {
		if($("#forgetloginId").val()==""){
			$('#message').html("請輸入帳號!");
			return false;
		}
		if($("#forgetIdentity").val()==""){
			$('#message').html("請輸入身份證字號!");
			return false;
		}
		var form = $('#forgetForm');
		form.attr('action', 'home!forgetPassword.action');
		form.submit();
	});
	
	$("#forget-reset").click(function(){
		$("#forgetLoginId").val("");
		$("#forgetIdentity").val("");
		$("#forgetMessage").text("");
		return false;
	});
	
	//for forgetPasswordEdit
	$('#editPasswordBtn').click(function() {
		if($('#newPassword').val() == "" || $('#reNewPassword').val() == "") {
			alert('請輸入密碼!!');
			return false;
		}
		if($('#newPassword').val() != $('#reNewPassword').val()) {
			alert('資料有誤!!');
			$('#newPassword').val('');
			$('#reNewPassword').val('');
			return false;
		}
		var form = $('#passwordEditForm');
		form.attr('action', 'login!editForgetPassword.action');
		form.submit();
	});
	
});	